package cn.hznc.controller.device;

import cn.hznc.controller.service.device.DeviceService;
import cn.hznc.domain.request.device.DeviceRunAndOpenRateReq;
import cn.hznc.domain.request.device.DeviceRunningReq;
import cn.hznc.domain.response.ResponseBody;
import cn.hznc.mapper.MachineToolStatusDailyInfoMapper;
import cn.hznc.mapper.MachineToolStatusMapper;
import cn.hznc.repository.WarehouseRespository;
import cn.hznc.utils.CommonUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;

/**
 * @Author：Administrator
 * @Date：2023/10/10 11:08
 */
@RestController
@Slf4j
@CrossOrigin(origins = "*", maxAge = 3600)
public class DeviceController{

    @Autowired
    private DeviceService deviceService;

    @Resource
    private MachineToolStatusDailyInfoMapper statusDailyInfoMapper;

    @Resource
    private MachineToolStatusMapper machineToolStatusMapper;

    @Resource
    private WarehouseRespository warehouseRespository;

    SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");

    @RequestMapping(value = "/deviceRunning", method = RequestMethod.POST)
    public ResponseBody deviceRunning(@RequestBody DeviceRunningReq deviceRunningReq) {
        return ResponseBody.success(deviceService.deviceRunning2Reload(deviceRunningReq));
    }

    @RequestMapping(value = "/deviceOpening", method = RequestMethod.POST)
    public ResponseBody deviceOpening(@RequestBody DeviceRunningReq deviceRunningReq) {
        return ResponseBody.success(deviceService.deviceOpeningReload(deviceRunningReq));
    }

    @RequestMapping(value = "/device/running", method = RequestMethod.POST)
    public ResponseBody deviceRunningRate(@RequestBody DeviceRunAndOpenRateReq deviceRunAndOpenRateReq) {
        return ResponseBody.success(deviceService.deviceRunningRate(deviceRunAndOpenRateReq));
    }

    @RequestMapping(value = "/device/getWorkTime", method = RequestMethod.GET)
    public ResponseBody getWorkTime() {
        return ResponseBody.success(deviceService.getWorkTime());
    }



    @RequestMapping(value = "/device/opening", method = RequestMethod.POST)
    public ResponseBody deviceOpeningRate(@RequestBody DeviceRunningReq deviceRunningReq) {
        return ResponseBody.success(deviceService.deviceOpeningReload(deviceRunningReq));
    }

    @RequestMapping(value = "/deviceStateGantt", method = RequestMethod.POST)
    public ResponseBody deviceStateGantt(@RequestBody DeviceRunningReq deviceRunningReq) {
        return ResponseBody.success(deviceService.deviceStateGanttReload(deviceRunningReq));
    }


}
